package com.gee.spring.cloud.feign.flow.execute.nextwork;

import com.gee.spring.cloud.feign.flow.work.AbstractWork;

/**
 * desc:
 *
 * @author gee
 * @since 2021-03-16 16:01:33
 */

public class NextWorkWrapper<R> {

    private AbstractWork<?> work;

    private Boolean necessaryForNext;

    private Condition<R> condition;

    private NextWorkWrapper(AbstractWork<?> work, boolean necessaryForNext, Condition<R> condition) {
        this.work = work;
        this.necessaryForNext = necessaryForNext;
        this.condition = condition;
    }

    public AbstractWork<?> getWork() {
        return work;
    }

    public void setWork(AbstractWork<?> work) {
        this.work = work;
    }

    public Boolean getNecessaryForNext() {
        return necessaryForNext;
    }

    public void setNecessaryForNext(Boolean necessaryForNext) {
        this.necessaryForNext = necessaryForNext;
    }

    public Condition<R> getCondition() {
        return condition;
    }

    public void setCondition(Condition<R> condition) {
        this.condition = condition;
    }

    public static <R> NextWorkWrapper<R> build(AbstractWork<?> work){
        return new NextWorkWrapper<>(work, true, new SimpleCondition<>());
    }

    public static <R> NextWorkWrapper<R> build(AbstractWork<?> work, boolean necessaryForNext){
        return new NextWorkWrapper<>(work, necessaryForNext, new SimpleCondition<>());
    }

    public static <R> NextWorkWrapper<R> build(AbstractWork<?> work, Condition<R> condition){
        return new NextWorkWrapper<>(work, true, condition);
    }

    public static <R> NextWorkWrapper<R> build(AbstractWork<?> work, boolean necessaryForNext,
                                                   Condition<R> condition){
        return new NextWorkWrapper<>(work, necessaryForNext, condition);
    }
}
